package com.tykj.yangningyu.chatdemo;

import android.content.Intent;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.avos.avoscloud.im.v2.AVIMClient;
import com.avos.avoscloud.im.v2.AVIMException;
import com.avos.avoscloud.im.v2.callback.AVIMClientCallback;

import butterknife.BindView;
import butterknife.OnClick;

public class LoginActivity extends BaseActivity {

    @BindView(R.id.username)
    EditText username;
    @BindView(R.id.login)
    Button login;

    @Override
    protected void initView() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_login;
    }


    @OnClick(R.id.login)
    public void onClick() {
        String name = username.getText().toString().trim();
        AVIMClient instance = AVIMClient.getInstance(name);
        instance.open(new AVIMClientCallback() {
            @Override
            public void done(AVIMClient avimClient, AVIMException e) {
                if (null != avimClient) {
                    Toast.makeText(LoginActivity.this, "success", Toast.LENGTH_SHORT).show();
                    ChatApp.mClient = avimClient;
                    startActivity(new Intent(LoginActivity.this,MainActivity.class));
                }
            }
        });
    }
}
